//
//  HMStatus.swift
//
//
//  Created by lst on 16/5/26.
//
//

import UIKit

class HMStatus: NSObject {
    //自动匹配机型对应的平台
    //4 4s 5 5c 都是32的
    //之后的都是 64位
    
    var id: Int64 = 0
    //微博信息内容
    var text: String?
    ///微博创建时间
    var created_at: String?
    ///微博来源
    var source: String?
    //用户信息(模型存在)
    var user: HMUser?
    //转发微博属性
    var retweeted_status: HMStatus?
    //转发的数量
    var reposts_count: Int = 0
    //评论
    var comments_count: Int = 0
    //赞
    var attitudes_count: Int = 0
    
    //配图视图的模型数组
    var pic_urls: [HMPicture]?
    //kvc
    init(dict: [String : AnyObject]){
        super.init()
        setValuesForKeysWithDictionary(dict)
        
    }
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user" {
            if let dict = value as? [String : AnyObject]{
                user = HMUser(dict:dict)
                
            }
            //需要添加return  不然字典转模型就白做了
            return
            
            
        }
        //给转发微博做字典转模型
        if key == "retweeted_status" {
            if let dict = value as? [String : AnyObject] {
                retweeted_status = HMStatus(dict: dict)
            }
            //需要添加return  不然字典转模型就白做了
            return
        }
        if key == "pic_urls"{
            //将value转化成数组
            if let array = value as? [[String : AnyObject]]{
                //遍历数组
                var temparray = [HMPicture]()
                for item in array {
                    //字典转模型
                    let p = HMPicture(dict: item)
                    //添加到模型数组中
                    temparray.append(p)
                }
                //复制保存
                pic_urls = temparray
            }
            return
          
        }
        //增加效率
        super.setValue(value, forKey: key)
    }
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {    }
}
